package com.endbd.purchase.purchase_order.service.impl;

import com.endbd.feignapi.model.purchase.CDetails;
import com.endbd.feignapi.model.purchase.CPurchase;
import com.endbd.purchase.purchase_order.dao.PurchaseDao;
import com.endbd.purchase.purchase_order.model.PurchaseData;
import com.endbd.purchase.purchase_order.model.PurchaseOrderCondition;
import com.endbd.purchase.purchase_order.service.PDMLService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Auther:Lang
 * @Date:2022-11-18
 * @Time:14:38
 * @Description:采购单审核DML操作的业务逻辑层
 */

@Service
@Transactional(rollbackFor = Exception.class,propagation = Propagation.REQUIRED,isolation = Isolation.DEFAULT)
public class DMLService implements PDMLService {
    @Autowired
    private PurchaseDao purchaseDao;

    @Override
    public int addAuditNameByPurchaseId(String purchaseId, Integer uid) {
        return purchaseDao.addAuditById(purchaseId,uid);
    }

    @Override
    public int delByPurchaseId(String purchaseId) {
        List<PurchaseData> purchaseData = purchaseDao.queryPurchaseDetailById(purchaseId);
        if (purchaseData.size()>0){
            int i = purchaseDao.delDetailByPurchaseIdAndProductId(purchaseId);
        }
        return purchaseDao.delPurchaseById(purchaseId);
    }

    @Override
    public int auditById(PurchaseOrderCondition conn) {
        return purchaseDao.auditPurchaseById(conn);
    }

    @Override
    public int addPurchaseOrder(CPurchase purchase) {
        return  purchaseDao.addPurchaseOrder(purchase);
    }

    @Override
    public int addPurchaseDetail(List<CDetails> details) {
        return purchaseDao.addPurchaseDetail(details);
    }

    @Override
    public int delDetailByPurchaseIdAndProductId(String purchaseId) {
        return   purchaseDao.delDetailByPurchaseIdAndProductId(purchaseId);
    }

    @Override
    public int updateWarehouseIdAndRkStatus(PurchaseOrderCondition opc) {
        return purchaseDao.updateWarehouseIdAndRkStatus(opc);
    }
}
